<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是初次使用Git前的一些相关配置的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV01-Git-03-首次运行Git前的配置">
<meta property="og:url" content="https://sumumm.github.io/post/85780aad.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是初次使用Git前的一些相关配置的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622071057360.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201201144852500.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201201121224576.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201201144959530.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622073618153.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622073953717.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622074503504.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130105615567.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130110553797.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130114836968.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/2020113011502931.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130115648917.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/WindowsLoadUbuntu.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622075604500.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108212328636.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108213009689.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108220705441.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108221913272.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/VersionControl/Git-01/image-20220108222227365.png">
<meta property="article:published_time" content="2023-07-02T07:14:15.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.069Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622071057360.png">


<link rel="canonical" href="https://sumumm.github.io/post/85780aad.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/85780aad.html","path":"post/85780aad.html","title":"LV01-Git-03-首次运行Git前的配置"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV01-Git-03-首次运行Git前的配置 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">一、配置文件</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%9C%A8Linux%E4%B8%8A%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">1. 在Linux上的配置文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%9C%A8Windows%E4%B8%AD%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">2. 在Windows中的配置文件</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE"><span class="nav-text">二、基本配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF"><span class="nav-text">1. 用户信息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91%E5%99%A8"><span class="nav-text">2. 文本编辑器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%A3%80%E6%9F%A5%E9%85%8D%E7%BD%AE%E4%BF%A1%E6%81%AF"><span class="nav-text">3. 检查配置信息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%AF%B9LF%E5%92%8CCRLF%E7%9A%84%E5%A4%84%E7%90%86"><span class="nav-text">4. 对LF和CRLF的处理</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81GitHub"><span class="nav-text">三、GitHub</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-GitHub%E6%98%AF%E5%95%A5%EF%BC%9F"><span class="nav-text">1. GitHub是啥？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-SSH"><span class="nav-text">2. SSH</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E4%BB%80%E4%B9%88%E6%98%AFSSH%EF%BC%9F"><span class="nav-text">2.1 什么是SSH？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E7%99%BB%E5%BD%95%E6%96%B9%E5%BC%8F"><span class="nav-text">2.2 登录方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-SSH%E6%9C%8D%E5%8A%A1%E5%AE%89%E8%A3%85"><span class="nav-text">2.3 SSH服务安装</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-1-%E5%9C%A8Linux%E4%B8%8A%E4%BD%BF%E7%94%A8SSH"><span class="nav-text">2.3.1 在Linux上使用SSH</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-2-%E5%9C%A8Windows%E4%B8%8A%E4%BD%BF%E7%94%A8SSH"><span class="nav-text">2.3.2 在Windows上使用SSH</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-Windows%E7%BB%88%E7%AB%AF%E7%99%BB%E5%BD%95Ubuntu"><span class="nav-text">2.4 Windows终端登录Ubuntu</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-1-%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%BC%8F%E9%85%8D%E7%BD%AE"><span class="nav-text">2.4.1 虚拟机网络模式配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-2-%E6%9F%A5%E7%9C%8Bwindows%E5%92%8CUbuntu%E7%BD%91%E7%BB%9C%E5%9C%B0%E5%9D%80"><span class="nav-text">2.4.2 查看windows和Ubuntu网络地址</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-3-%E6%98%AF%E5%90%A6%E8%83%BDping%E9%80%9A%EF%BC%9F"><span class="nav-text">2.4.3 是否能ping通？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-4-%E7%99%BB%E5%BD%95Ubuntu"><span class="nav-text">2.4.4 登录Ubuntu</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-5-%E7%99%BB%E5%BD%95%E6%88%90%E5%8A%9F%E7%9A%84%E6%95%88%E6%9E%9C"><span class="nav-text">2.4.5 登录成功的效果</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-SSH%E8%AE%BF%E9%97%AEGitHub"><span class="nav-text">3. SSH访问GitHub</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E6%A3%80%E6%9F%A5SSH%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E8%BF%9E%E6%8E%A5GitHub"><span class="nav-text">3.1 检查SSH是否可以连接GitHub</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E5%AE%89%E8%A3%85-ssh-keys"><span class="nav-text">3.2 安装 ssh keys </span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E9%85%8D%E7%BD%AE%E8%84%9A%E6%9C%AC"><span class="nav-text">四、配置脚本</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%AE%89%E8%A3%85Git"><span class="nav-text">1. 安装Git</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%AE%89%E8%A3%85SSH%E6%9C%8D%E5%8A%A1"><span class="nav-text">2. 安装SSH服务</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E9%85%8D%E7%BD%AEGit"><span class="nav-text">3. 配置Git</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/85780aad.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV01-Git-03-首次运行Git前的配置 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV01-Git-03-首次运行Git前的配置
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-02 15:14:15" itemprop="dateCreated datePublished" datetime="2023-07-02T15:14:15+08:00">2023-07-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/" itemprop="url" rel="index"><span itemprop="name">开发工具</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/" itemprop="url" rel="index"><span itemprop="name">03版本控制</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6.7k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>24 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是初次使用Git前的一些相关配置的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">Git 官网</td><td align="left"><a href="https://git-scm.com/" target="_blank">https://git-scm.com/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 官方文档</td><td align="left"><a href="https://git-scm.com/doc" target="_blank">https://git-scm.com/doc <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Pro Git Book</td><td align="left"><a href="https://git-scm.com/book/zh/v2" target="_blank">https://git-scm.com/book/zh/v2 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 快速使用指南</td><td align="left"><a href="https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/" target="_blank">https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Visual Git Cheat Sheet</td><td align="left"><a href="https://ndpsoftware.com/git-cheatsheet.html#loc=index" target="_blank">https://ndpsoftware.com/git-cheatsheet.html#loc=index <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<h1 id="一、配置文件"><a href="#一、配置文件" class="headerlink" title="一、配置文件"></a><font size=3>一、配置文件</font></h1><p>Git 自带一个 <code>git config</code> 的工具来帮助设置控制 Git 外观和行为的配置变量。</p>
<h2 id="1-在Linux上的配置文件"><a href="#1-在Linux上的配置文件" class="headerlink" title="1. 在Linux上的配置文件"></a><font size=3>1. 在Linux上的配置文件</font></h2><p>（1）<code>/etc/gitconfig</code> 文件:：包含系统上每一个用户及他们仓库的通用配置。 如果在执行 <code>git config</code> 时带上 <code>--system</code> 选项，那么它就会读写该文件中的配置变量。 （由于它是系统配置文件，因此需要管理员或超级用户权限来修改它，但是默认好像不会创建这个文件，有需要的话需要自己创建）</p>
<p>（2）<code>~/.gitconfig</code> 或 <code>~/.config/git/config</code> 文件：只针对当前用户。 可以传递 <code>--global</code> 选项让 Git 读写此文件，这会对系统上 <strong>所有</strong> 的仓库生效。</p>
<p>（3）当前使用仓库的 Git 目录中的 <code>config</code> 文件（即 <code>.git/config</code>）：针对该仓库。 可以传递 <code>--local</code> 选项让 Git 强制读写此文件，虽然默认情况下用的就是它。 （当然，需要进入某个 Git 仓库中才能让该选项生效。）</p>
<p>注意：每一个级别会覆盖上一级别的配置，所以 <code>.git/config</code> 的配置变量会覆盖 <code>/etc/gitconfig</code> 中的配置变量。</p>
<p>我们可以通过以下命令查看所有的配置以及它们所在的文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --list --show-origin</span><br></pre></td></tr></table></figure>

<h2 id="2-在Windows中的配置文件"><a href="#2-在Windows中的配置文件" class="headerlink" title="2. 在Windows中的配置文件"></a><font size=3>2. 在Windows中的配置文件</font></h2><p>在 Windows 系统中，Git 会查找 <code>$HOME</code> 目录下（一般情况下是 <code>C:\Users\$USER</code> ）的 <code>.gitconfig</code> 文件。 Git 同样也会寻找 <code>/etc/gitconfig</code> 文件，但只限于 MSys 的根目录下，即安装 Git 时所选的目标位置。 </p>
<p>如果我们在 Windows 上使用 Git 2.x 以后的版本，那么还有一个系统级的配置文件，Windows XP 上在 <code>C:\Documents and Settings\All Users\Application Data\Git\config</code> ，Windows Vista 及其以后的版本在 <code>C:\ProgramData\Git\config</code> 。此文件只能以管理员权限通过 <code>git config -f &lt;file&gt;</code> 来修改。</p>
<p>我们可以通过以下命令查看所有的配置以及它们所在的文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --list --show-origin</span><br></pre></td></tr></table></figure>

<p>如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622071057360.png" alt="image-20230622071057360" style="zoom: 33%;" />

<h1 id="二、基本配置"><a href="#二、基本配置" class="headerlink" title="二、基本配置"></a><font size=3>二、基本配置</font></h1><h2 id="1-用户信息"><a href="#1-用户信息" class="headerlink" title="1. 用户信息"></a><font size=3>1. 用户信息</font></h2><p>安装完 Git 之后，要做的第一件事就是设置用户名和邮件地址。 这一点很重要，因为每一个 Git 提交都会使用这些信息，它们会写入到我们的每一次提交中，不可更改：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name &quot;John Doe&quot;</span><br><span class="line">git config --global user.email johndoe@example.com</span><br></pre></td></tr></table></figure>

<p>如果使用了 <code>--global</code> 选项，那么该命令只需要运行一次，因为之后无论在该系统上做任何事情， Git 都会使用那些信息。 当想针对特定项目使用不同的用户名称与邮件地址时，可以在那个项目目录下运行没有 <code>--global</code> 选项的命令来配置。很多 GUI 工具都会在第一次运行时帮助我们配置这些信息。</p>
<h2 id="2-文本编辑器"><a href="#2-文本编辑器" class="headerlink" title="2. 文本编辑器"></a><font size=3>2. 文本编辑器</font></h2><p>我们还可以配置默认文本编辑器，当 Git 需要我们输入信息时会调用它。 如果未配置，Git 会使用操作系统默认的文本编辑器。如果想使用不同的文本编辑器，例如 Emacs，可以这样做：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global core.editor emacs</span><br></pre></td></tr></table></figure>

<p>在 Windows 系统上，如果想要使用别的文本编辑器，那么必<strong>须指定可执行文件的完整路径</strong>。 它可能随我们的编辑器的打包方式而不同。对于 Notepad++ ，一个流行的代码编辑器来说，我们可能想要使用 32 位的版本， 因为在《Pro Git Book》这本书编写时 64 位的版本尚不支持所有的插件。 如果我们在使用 32 位的 Windows 系统，或在 64 位系统上使用 64 位的编辑器，那么你需要输入如下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global core.editor &quot;&#x27;C:/Program Files/Notepad++/notepad++.exe&#x27; -multiInst -notabbar -nosess</span><br></pre></td></tr></table></figure>

<p>【说明】vim、Emacs 和 Notepad++ 都是流行的文本编辑器，通常程序员们会在 Linux 和 macOS 这类基于 Unix 的系统或 Windows 系统上使用它们。 如果我们在使用其他的或 32 位版本的编辑器，可以在 <a target="_blank" rel="noopener" href="https://git-scm.com/book/zh/v2/ch00/ch_core_editor">git config core.editor 命令</a> 中查看设置为该编辑器的具体步骤。</p>
<h2 id="3-检查配置信息"><a href="#3-检查配置信息" class="headerlink" title="3. 检查配置信息"></a><font size=3>3. 检查配置信息</font></h2><p>如果想要检查我们的配置，可以使用 <code>git config --list</code> 命令来列出所有 Git 当时能找到的配置。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git config --list</span></span><br><span class="line">user.name=John Doe</span><br><span class="line">user.email=johndoe@example.com</span><br><span class="line">color.status=auto</span><br><span class="line">color.branch=auto</span><br><span class="line">color.interactive=auto</span><br><span class="line">color.diff=auto</span><br><span class="line">...</span><br></pre></td></tr></table></figure>

<p>我们可能会看到重复的变量名，因为 Git 会从不同的文件中读取同一个配置（例如：<code>/etc/gitconfig</code> 与 <code>~/.gitconfig</code>）。 这种情况下，Git 会使用它找到的每一个变量的最后一个配置。我们还可以通过输入 <code>git config &lt;key&gt;</code>： 来检查 Git 的某一项配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git config user.name</span></span><br><span class="line">John Doe</span><br></pre></td></tr></table></figure>

<p>由于 Git 会从多个文件中读取同一配置变量的不同值，因此我们可能会在其中看到意料之外的值而不知道为什么。 此时，我们可以查询 Git 中该变量的 <strong>原始</strong> 值，它会告诉我们哪一个配置文件最后设置了该值：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git config --show-origin rerere.autoUpdate</span></span><br><span class="line">file:/home/johndoe/.gitconfig	false</span><br></pre></td></tr></table></figure>

<h2 id="4-对LF和CRLF的处理"><a href="#4-对LF和CRLF的处理" class="headerlink" title="4. 对LF和CRLF的处理"></a><font size=3>4. 对<code>LF</code>和<code>CRLF</code>的处理</font></h2><p><code>Linux</code>系统和<code>Windows</code>系统下的换行符不一样，<code>Linux</code>是<code>\n</code>，即<code>LF</code>，<code>Windows</code>下面是<code>\r\n</code>，即<code>CRLF</code>，<code>git</code>在维护版本库的时候统一使用的是<code>LF</code>。所以当文档跨平台进行编辑的时候，换行符就会产生差别，在不同平台编辑过得文件在进行<code>commit</code>的时候也会有相应的换行符警告。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LF will be replaced by CRLF in .......</span><br></pre></td></tr></table></figure>

<p>那么怎么处理呢？这样就可以了（不过这样似乎只是治标不治本，仅仅是忽略了检查，要是文章的话还好，要是代码的话，有可能会因为换行符而出现问题，暂时先这样解决）。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global core.autocrlf false</span><br></pre></td></tr></table></figure>

<h1 id="三、GitHub"><a href="#三、GitHub" class="headerlink" title="三、GitHub"></a><font size=3>三、GitHub</font></h1><h2 id="1-GitHub是啥？"><a href="#1-GitHub是啥？" class="headerlink" title="1. GitHub是啥？"></a><font size=3>1. GitHub是啥？</font></h2><p>GitHub 是最大的 Git 版本库托管商，是成千上万的开发者和项目能够合作进行的中心。 大部分 Git 版本库都托管在 GitHub，很多开源项目使用 GitHub 实现 Git 托管、问题追踪、代码审查以及其它事情。 所以，尽管这不是 Git 开源项目的直接部分，但如果想要专业地使用 Git，我们将不可避免地与 GitHub 打交道，所以这依然是一个绝好的学习机会。</p>
<h2 id="2-SSH"><a href="#2-SSH" class="headerlink" title="2. SSH"></a><font size=3>2. SSH</font></h2><h3 id="2-1-什么是SSH？"><a href="#2-1-什么是SSH？" class="headerlink" title="2.1 什么是SSH？"></a><font size=3>2.1 什么是SSH？</font></h3><p><code>SSH</code>为<code>Secure Shell</code>的缩写，由<code>IETF</code>的网络小组（<code>Network Working Group</code>）所制定，是一种加密的<strong>网络传输协议</strong>，可在不安全的网络中为网络服务提供安全的传输环境,其保证数据安全的原理是<strong>非对称加密</strong>。</p>
<table>
    <tr>
        <td align="center" width=120px>对称加密</td>
        <td align="left">&emsp;&emsp;使用的是一套秘钥，数据的加密以及解密用的都是同一套秘钥，当所有的客户端以及服务端都需要保存这套秘钥时，泄露的风险很高，而一旦秘钥便泄露便保证不了数据安全。</td>
    </tr>
    <tr>
        <td align="left">非对称加密</td>
        <td align="left">&emsp;&emsp;包含两套秘钥——公钥以及私钥，其中公钥用来加密，私钥用来解密，并且通过公钥计算不出私钥，因此私钥谨慎保存在服务端，而公钥可以随便传递，即使泄露也无风险。</td>
    </tr>
</table>

<p><code>SSH</code>在正确使用时可弥补网络中的漏洞；<code>SSH</code>是目前较可靠，专为远程登录会话和其他网络服务提供安全性的协议；利用<code>SSH</code>协议可以有效防止远程管理过程中的信息泄露问题。</p>
<p><code>SSH</code>最初是<code>UNIX</code>系统上的一个程序，后来又迅速扩展到其他操作平台。<code>SSH</code>客户端适用于多种平台。几乎所有<code>UNIX</code>平台—包括<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/HP-UX"><code>HP-UX</code></a>、<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/Linux"><code>Linux</code></a>、<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/AIX"><code>AIX</code></a>、<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/Solaris/3517"><code>Solaris</code></a>、<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/UNIX"><code>Digital UNIX</code></a>、<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/Irix"><code>Irix</code></a>，以及其他平台，都可运行<code>SSH</code>。</p>
<h3 id="2-2-登录方式"><a href="#2-2-登录方式" class="headerlink" title="2.2 登录方式"></a><font size=3>2.2 登录方式</font></h3><table>
    <tr>
        <td align="center" width=110px>方式</td>
        <td align="center">说明</td>
    </tr>
    <tr>
        <td align="left">密码登录</td>
        <td align="left">1.服务端收到登录请求后，首先互换公钥;<br>
2.客户端用服务端的公钥加密账号密码并发送;<br>
3.服务端用自己的秘钥解密后得到账号密码，然后进行验证;<br>
4.服务端用客户端的公钥加密验证结果并返回;<br>
5.客户端用自己的秘钥解密后得到验证结果.</td>
    </tr>
    <tr>
        <td align="left">公钥登录<br>(证书登录)</td>
        <td align="left">1.客户端用户必须手动地将自己的公钥添加到服务器一个名叫authorized_keys的文件里，顾名思义，这个文件保存了所有可以远程登录的机器的公钥;<br>
2.客户端发起登录请求，并且发送一个自己公钥的指纹（具有唯一性，但不是公钥）;<br>
3.服务端根据指纹检测此公钥是否保存在authorized_keys中;<br>
4.若存在，服务端便生成一段随机字符串，然后利用客户端公钥加密并返回;<br>
5.客户端收到后用自己的私钥解密，再利用服务端公钥加密后发回;<br>
6.服务端收到后用自己的私钥解密，如果为同一字符串，则验证通过.</td>
    </tr>
</table>


<p>【参考文章】</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://hyrepo.com/tech/ssh-works/">图解<code>SSH</code>原理及两种登录方式</a></li>
<li><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=mF6J-VQHPxA"><code>Intro to SSH and SSH Keys</code></a></li>
<li><a target="_blank" rel="noopener" href="http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html"><code>SSH</code>原理与运用（一）：远程登录</a></li>
</ul>
<h3 id="2-3-SSH服务安装"><a href="#2-3-SSH服务安装" class="headerlink" title="2.3 SSH服务安装"></a><font size=3>2.3 SSH服务安装</font></h3><h4 id="2-3-1-在Linux上使用SSH"><a href="#2-3-1-在Linux上使用SSH" class="headerlink" title="2.3.1 在Linux上使用SSH"></a><font size=3>2.3.1 在Linux上使用SSH</font></h4><ul>
<li>（1）查询是否安装SSH服务端，可以使用以下命令</li>
</ul>
 <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ps -e |grep ssh</span><br></pre></td></tr></table></figure>

<p>查询情况如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201201144852500.png" style="zoom:67%;" />

<p>终端返回结果中没有 sshd，则说明系统还没有安装 ssh-server 服务，后续对ssh进行安装</p>
<ul>
<li>（2）若是没有安装SSH服务端，可以使用以下命令安装ssh服务</li>
</ul>
 <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install openssh-server</span><br></pre></td></tr></table></figure>

<ul>
<li>（3）检查SSH服务端是否安装成功</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ps -e |grep ssh</span><br></pre></td></tr></table></figure>

<p>安装情况如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201201121224576.png" alt="ssh安装情况" style="zoom:50%;" />

<p>出现了sshd，说明ssh服务已经正常启动了，若安装完毕后，还是没有sshd出现，那么就进行下一步，手动启动ssh服务。</p>
<ul>
<li>（4）启动 ssh服务</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo /etc/init.d/ssh start </span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201201144959530.png" alt="启动ssh" style="zoom:67%;" />

<p>运行完毕之后，重新查询ssh服务即可。</p>
<blockquote>
<p>SSH服务常用相关命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo /etc/init.d/ssh stop  # 停止服务</span><br><span class="line">sudo /etc/init.d/ssh start # 启动服务</span><br><span class="line">sudo /etc/init.d/sshresart # 重启服务</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="2-3-2-在Windows上使用SSH"><a href="#2-3-2-在Windows上使用SSH" class="headerlink" title="2.3.2 在Windows上使用SSH"></a><font size=3>2.3.2 在Windows上使用SSH</font></h4><p>Windows中，SSH服务好像是系统自带的功能，我使用的时候是直接就用了，默认是开启的，但是有的时候默认可能关闭，这个时候我们按以下步骤操作：</p>
<ul>
<li>（1）检查SSH，我们打开命令行，输入ssh查看是否有输出信息</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622073618153.png" alt="image-20230622073618153" style="zoom:45%;" />

<p>我的电脑之前开启过，多以这里会输出ssh命令的使用帮助，但是若是出现类似找不到命令之类的，那就说明SSH服务没有开启。若是没有开启那就执行后边的步骤。</p>
<ul>
<li>（2）之后的Windows10或者Windows11版本已经支持OpenSSH服务。默认程序已经安装好了OpenSSH 客户端，【Windows设置】&rarr;【应用】&rarr;【应用和功能】&rarr;【可选功能】就可看到系统已经安装好的可选功能，如下图所示</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622073953717.png" alt="image-20230622073953717" style="zoom: 30%;" />

<p>若在已安装列表里面没有OpenSSH 服务端，单击添加功能找到OpenSSH 服务端等待安装完毕即可，下载完毕根据提示可能需要重启电脑（有需要的话就重启，不需要就算了）。之后，就可以再次在cmd中键入ssh查看自己的ssh服务是否已成功启动。若安装完后，cmd中还是没有上图中的显示，则考虑是环境变量的问题。</p>
<ul>
<li>（3）开启SSH服务，【Win+S】&rarr;【键入服务】&rarr;【打开本地服务界面】&rarr;【找到OpenSSH SSH Server】&rarr;【启动方式改为自动】</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622074503504.png" alt="image-20230622074503504" style="zoom:33%;" />

<h3 id="2-4-Windows终端登录Ubuntu"><a href="#2-4-Windows终端登录Ubuntu" class="headerlink" title="2.4 Windows终端登录Ubuntu"></a><font size=3>2.4 Windows终端登录Ubuntu</font></h3><h4 id="2-4-1-虚拟机网络模式配置"><a href="#2-4-1-虚拟机网络模式配置" class="headerlink" title="2.4.1 虚拟机网络模式配置"></a><font size=3>2.4.1 虚拟机网络模式配置</font></h4><ul>
<li>VMware中虚拟网络编辑器设置如下</li>
</ul>
<p> <img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130105615567.png" alt="虚拟网络编辑器"></p>
<ul>
<li>虚拟机的网络适配器也需改为桥接模式</li>
</ul>
<h4 id="2-4-2-查看windows和Ubuntu网络地址"><a href="#2-4-2-查看windows和Ubuntu网络地址" class="headerlink" title="2.4.2 查看windows和Ubuntu网络地址"></a><font size=3>2.4.2 查看windows和Ubuntu网络地址</font></h4><ul>
<li>Windows：<code>ipconfig</code></li>
<li>Ubuntu： <code>ifconfig</code></li>
</ul>
<p>若Ubuntu出现以下情况，安装net-tools即可,安装命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install net-tools</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130110553797.png" alt="net-tools安装" style="zoom:76%;" />

<ul>
<li>记录下Ubuntu的IP地址，如下图。</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130114836968.png" alt="查看ip" style="zoom:50%;" />

<h4 id="2-4-3-是否能ping通？"><a href="#2-4-3-是否能ping通？" class="headerlink" title="2.4.3 是否能ping通？"></a><font size=3>2.4.3 是否能ping通？</font></h4><p>ssh服务远程登录需要保证两个IP可以ping通，也就是可以正常的通信，我们可以使用命令，在Windows命令行执行以下命令和Ubuntu的终端，后边的ip要写对方的IP地址，保证两者可以互相ping通。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ping &lt;ip-address&gt;</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/2020113011502931.png" alt="window通信检测" style="zoom:60%;" />



<h4 id="2-4-4-登录Ubuntu"><a href="#2-4-4-登录Ubuntu" class="headerlink" title="2.4.4 登录Ubuntu"></a><font size=3>2.4.4 登录Ubuntu</font></h4><p>我们在Windows的命令行中执行以下命令登录VMware中的Ubuntu：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh user-name@ip-address</span><br></pre></td></tr></table></figure>

<p>首次登录会出现如下提示，输入用户密码即可。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/20201130115648917.png" alt="首次登录ubuntu" style="zoom:60%;" />

<h4 id="2-4-5-登录成功的效果"><a href="#2-4-5-登录成功的效果" class="headerlink" title="2.4.5 登录成功的效果"></a><font size=3>2.4.5 登录成功的效果</font></h4><p>登录过程中可能会提示输入密码，如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/WindowsLoadUbuntu.png" alt="登录成功" style="zoom: 50%;" />

<p>由于是整理之前的笔记，我重新登陆了一下，不过此时换成了ubuntu的名字发生了变化罢了：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20230622075604500.png" alt="image-20230622075604500" style="zoom: 30%;" />

<h2 id="3-SSH访问GitHub"><a href="#3-SSH访问GitHub" class="headerlink" title="3. SSH访问GitHub"></a><font size=3>3. SSH访问GitHub</font></h2><p>到这一部分的时候，在Linux下或者Windows中执行的命令都是一样的，最多就是文件位置或者打印信息可能有所区别，这里以Ubuntu（内核为Linux）为例说明。</p>
<h3 id="3-1-检查SSH是否可以连接GitHub"><a href="#3-1-检查SSH是否可以连接GitHub" class="headerlink" title="3.1 检查SSH是否可以连接GitHub"></a><font size=3>3.1 检查SSH是否可以连接GitHub</font></h3><ul>
<li>我们可以通过以下命令检查ssh是否可以连接到GitHub</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -T git@github.com</span><br></pre></td></tr></table></figure>

<ul>
<li>连接失败的情况</li>
</ul>
<p>若出现以下提示，则不能连接到<code>github</code>，需要重新配置，按照后边配置即可。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">The authenticity of host &#x27;github.com (20.205.243.166)&#x27; can&#x27;t be established.</span><br><span class="line">ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.</span><br><span class="line">Are you sure you want to continue connecting (yes/no)? yes</span><br><span class="line">Warning: Permanently added &#x27;github.com,20.205.243.166&#x27; (ECDSA) to the list of known hosts.</span><br><span class="line">git@github.com: Permission denied (publickey).</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108212328636.png" alt="image-20220108212328636" style="zoom:67%;" />

<ul>
<li>连接成功的情况</li>
</ul>
<p>若连接成功，则会有如下提示，可以跳过后边的配置步骤，直接开始使用 Git。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hi qidaink! You&#x27;ve successfully authenticated, but GitHub does not provide shell access.</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108213009689.png" alt="image-20220108213009689" style="zoom:67%;" />

<h3 id="3-2-安装-ssh-keys"><a href="#3-2-安装-ssh-keys" class="headerlink" title="3.2 安装 ssh keys "></a><font size=3>3.2 安装 ssh keys </font></h3><p>【注意】：Linux下相关的文件在<code>~/.ssh</code>目录，在Windows中的话在<code>C:\Users\&lt;用户名&gt;\.ssh</code>这个目录，这里以Linux中的操作为例。</p>
<ul>
<li>（1）检查相应的文件是否存在</li>
</ul>
<p>主要是检查文件<code>id_rsa（私钥）</code>和<code>id_rsa.pub（公钥）</code>是否存在。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd ~/.ssh</span><br><span class="line">ls</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108220705441.png" alt="image-20220108220705441" style="zoom:67%;" />

<p>发现没有<code>id_rsa（私钥）</code>和<code>id_rsa.pub（公钥）</code>这两个文件，说明没有<code>ssh keys</code>。若有这两个文件，那么就移除当前的<code>id_rsa（私钥）</code>和<code>id_rsa.pub（公钥）</code>：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rm ~/.ssh/id_rsa*</span><br></pre></td></tr></table></figure>

<ul>
<li>（2）重新生成<code>id_rsa</code>和<code>id_rsa.pub</code></li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">一开始用的这个命令</span></span><br><span class="line">ssh-keygen -t rsa -C &quot;user&#x27;s github email address&quot;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">后来好像必须要用下边这个命令，后边会解释为什么</span></span><br><span class="line">ssh-keygen -t ed25519 -C &quot;user&#x27;s github email address&quot;</span><br></pre></td></tr></table></figure>

<p><code>user&#39;s github email address</code>就是自己注册<code>github</code>时的邮箱。执行后会出现以下提示信息，其中有两次是让用户选择文件生成位置及设置密码的，不输入，直接按三次<code>enter</code>按键，表示路径默认，不需要密码。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">Generating public/private rsa key pair.</span><br><span class="line">Enter file in which to save the key (/home/hk/.ssh/id_rsa): </span><br><span class="line">Enter passphrase (empty for no passphrase): </span><br><span class="line">Enter same passphrase again: </span><br><span class="line">Your identification has been saved in /home/hk/.ssh/id_rsa.</span><br><span class="line">Your public key has been saved in /home/hk/.ssh/id_rsa.pub.</span><br><span class="line">The key fingerprint is:</span><br><span class="line">SHA256:cfJKNOMTwZf3j6t7aqbEqosgtQ2z0d0PWe+TckfHsZQ 2038035593@qq.com</span><br><span class="line">The key&#x27;s randomart image is:</span><br><span class="line">+---[RSA 2048]----+</span><br><span class="line">|       ..  .     |</span><br><span class="line">|        ..o .   .|</span><br><span class="line">|        B.o. . E |</span><br><span class="line">|   . . + @ .  o.o|</span><br><span class="line">|  = . . S . . .+o|</span><br><span class="line">| . B   . * . o...|</span><br><span class="line">|. + .   . = = .. |</span><br><span class="line">| . . .   o oooo  |</span><br><span class="line">|    . oo. .++=   |</span><br><span class="line">+----[SHA256]-----+</span><br></pre></td></tr></table></figure>

<p>【注意】由于写笔记的时候时间比较早，上边的命令生成的秘钥可能会有问题，就是在后边使用<code>git clone</code>命令的时候可能会报以下错误：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ERROR: You&#x27;re using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.</span><br></pre></td></tr></table></figure>

<p>原来是<code>github</code>对<code>SSH</code>密钥做了升级（<a target="_blank" rel="noopener" href="https://github.blog/2021-09-01-improving-git-protocol-security-github/">Improving Git protocol security on GitHub</a>），原来的<code>SHA-1</code>等一些已经不支持了。所以我们可以生成新的<code>Ed25519</code>密钥对：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t ed25519 -C &quot;user&#x27;s github email address&quot;</span><br></pre></td></tr></table></figure>

<ul>
<li>（3）打开<code>~/.ssh</code>文件夹</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入文件夹</span></span><br><span class="line">cd ~/.ssh</span><br><span class="line">gedit id_rsa.pub</span><br></pre></td></tr></table></figure>

<p>会发现生成了id_rsa和id_rsa.pub文件，然后我们使用编辑器打开id_rsa.pub文件，并复制所有内容。</p>
<ul>
<li>（4）添加<code>ssh keys</code>到<code>github</code>：<a target="_blank" rel="noopener" href="https://github.com/settings/keys">【<code>Github</code>】&rarr;【登录账号】&rarr;【头像】&rarr;【<code>Setting</code>】&rarr;【<code>SSH and GPG keys </code>】&rarr;【<code>SSH keys</code>】&rarr;【<code>New SSH key</code>】</a></li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-03-%E9%A6%96%E6%AC%A1%E8%BF%90%E8%A1%8CGit%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE/img/image-20220108221913272.png" alt="image-20220108221913272" style="zoom:30%;" />

<p>添加完毕后会收到一封邮件，表示已经添加成功。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/VersionControl/Git-01/image-20220108222227365.png" alt="image-20220108222227365" style="zoom:50%;" />

<ul>
<li>（5）按<code>3.1节</code>再次检查是否可以正常连接</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -T git@github.com</span><br></pre></td></tr></table></figure>

<h1 id="四、配置脚本"><a href="#四、配置脚本" class="headerlink" title="四、配置脚本"></a><font size=3>四、配置脚本</font></h1><p>为了偷懒，我写了一个在ubuntu中配置Git的脚本，由于还带有一些其他功能，就直接看链接吧：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/my-software-config">my-software-config: 一些软件的配置文件或者系统的配置脚本 (gitee.com)</a></p>
<h2 id="1-安装Git"><a href="#1-安装Git" class="headerlink" title="1. 安装Git"></a><font size=3>1. 安装Git</font></h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装git</span></span><br><span class="line">function git_install_online()</span><br><span class="line">&#123;</span><br><span class="line">    cd ~</span><br><span class="line">    echo -e &quot;$&#123;INFO&#125;$&#123;PINK&#125;current path:$(pwd)$&#123;CLS&#125;&quot;</span><br><span class="line">    echo -e &quot;$&#123;INFO&#125;检查git是否安装...&quot;</span><br><span class="line">    if ! $(command -v git &gt;/dev/null 2&gt;&amp;1) ; then</span><br><span class="line">    	echo -e &quot;$&#123;ERR&#125;git 尚未安装!!!&quot;</span><br><span class="line">        read -p &quot;是否安装git?(默认选择继续,退出请输入n):&quot; ret</span><br><span class="line">        if [ &quot;$&#123;ret&#125;&quot; != &quot;n&quot; ];then</span><br><span class="line">            sudo add-apt-repository ppa:git-core/ppa</span><br><span class="line">            sudo apt update</span><br><span class="line">            sudo apt-get install git</span><br><span class="line">            echo -e &quot;$&#123;INFO&#125;安装完毕,当前git版本如下:&quot;</span><br><span class="line">        else</span><br><span class="line">            return</span><br><span class="line">        fi</span><br><span class="line">    else</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;git 已安装,当前git版本如下:&quot;</span><br><span class="line">    fi</span><br><span class="line">    git_version=$(git -v | sed -n &quot;1p&quot;)</span><br><span class="line">    echo $&#123;git_version&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="2-安装SSH服务"><a href="#2-安装SSH服务" class="headerlink" title="2. 安装SSH服务"></a><font size=3>2. 安装SSH服务</font></h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装ssh-server</span></span><br><span class="line">function ssh_server()</span><br><span class="line">&#123;</span><br><span class="line">    cd ~</span><br><span class="line">    echo -e &quot;$&#123;INFO&#125;$&#123;PINK&#125;current path:$(pwd)$&#123;CLS&#125;&quot;</span><br><span class="line">	ssh_info=$(ps -e | grep ssh | grep &quot;sshd&quot;)</span><br><span class="line">	if [ &quot;$&#123;ssh_info&#125;&quot; == &quot;&quot; ];then</span><br><span class="line">		echo -e &quot;$&#123;ERR&#125;ssh-server 尚未安装,准备安装 ssh-server...&quot;</span><br><span class="line">		sudo apt-get install openssh-server</span><br><span class="line">		sudo /etc/init.d/ssh start</span><br><span class="line">		echo -e &quot;$&#123;INFO&#125;ssh-server 安装完毕,信息如下:&quot;</span><br><span class="line">	else</span><br><span class="line">		echo -e &quot;$&#123;INFO&#125;ssh-server 已安装,信息如下:&quot;</span><br><span class="line">	fi</span><br><span class="line">	</span><br><span class="line">	ssh_info=$(ps -e | grep ssh | grep &quot;sshd&quot;)</span><br><span class="line">	echo $ssh_info</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="3-配置Git"><a href="#3-配置Git" class="headerlink" title="3. 配置Git"></a><font size=3>3. 配置Git</font></h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">配置git</span></span><br><span class="line">function git_config()</span><br><span class="line">&#123;</span><br><span class="line">    cd ~</span><br><span class="line">    echo -e &quot;$&#123;INFO&#125;$&#123;PINK&#125;current path:$(pwd)$&#123;CLS&#125;&quot;</span><br><span class="line">    if ! $(command -v git &gt;/dev/null 2&gt;&amp;1) ; then</span><br><span class="line">    	echo -e &quot;$&#123;ERR&#125;git 尚未安装,请先安装git!!!&quot;</span><br><span class="line">        return</span><br><span class="line">    else</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;git 已安装,当前git版本如下:&quot;</span><br><span class="line">    fi</span><br><span class="line">    git_version=$(git -v | sed -n &quot;1p&quot;)</span><br><span class="line">    echo $&#123;git_version&#125;</span><br><span class="line"></span><br><span class="line">    read -p &quot;是否需要配置git基本信息?(默认选择继续,不需要请输入n):&quot; ret</span><br><span class="line">    if [ &quot;$&#123;ret&#125;&quot; != &quot;n&quot; ];then</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;开始配置git基本信息...&quot;</span><br><span class="line">        read -p &quot;请输入 gitee 用户名: &quot; giteeuser</span><br><span class="line">        read -p &quot;请输入 gitee 邮箱: &quot; giteeemail</span><br><span class="line">        git config --global user.name &quot;$&#123;giteeuser&#125;&quot;</span><br><span class="line">        git config --global user.email &quot;$&#123;giteeemail&#125;&quot;</span><br><span class="line">        git config --global core.autocrlf false</span><br><span class="line">        git config --global alias.mylog &quot;log --graph --pretty=format:&#x27;%C(magenta)[%an]%C(reset) %C(red)%h%C(reset) : %C(green)%s%C(reset) %C(yellow)%d%C(reset) %C(blue)(%cr)%C(reset)&#x27; --abbrev-commit --date=relative&quot;</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;git基本信息完成,配置项如下：&quot;</span><br><span class="line">        git config --list --show-origin</span><br><span class="line">    fi</span><br><span class="line">    </span><br><span class="line">    read -p &quot;是否需要配置SSH?(默认选择继续,不需要请输入n):&quot; ret</span><br><span class="line">    if [ &quot;$&#123;ret&#125;&quot; != &quot;n&quot; ];then</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;开始检查SSH...&quot;</span><br><span class="line">        ssh -T git@gitee.com</span><br><span class="line">        read -p &quot;输出是否含有: git@gitee.com: Permission denied (publickey). ?(y or n)&quot; ret</span><br><span class="line">        if [ &quot;$&#123;ret&#125;&quot; = &quot;y&quot; ] || [ &quot;$&#123;ret&#125;&quot; = &quot;&quot; ]; then</span><br><span class="line">            echo -e &quot;$&#123;ERR&#125;SSH未安装,无法连接到 gitee!!!&quot;</span><br><span class="line">        else</span><br><span class="line">            echo -e &quot;$&#123;INFO&#125;SSH已安装,可正常使用!!!&quot;</span><br><span class="line">            read -p &quot;是否重新安装 SSH ?(默认退出,继续输入y)&quot; ret</span><br><span class="line">            if [ &quot;$&#123;ret&#125;&quot; != &quot;y&quot; ]; then</span><br><span class="line">                return</span><br><span class="line">            else</span><br><span class="line">                rm -rvf ~/.ssh</span><br><span class="line">            fi</span><br><span class="line">        fi</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;开始配置SSH(gitee)...&quot;</span><br><span class="line">        read -p &quot;请输入一个标识，可以是邮箱:&quot; sshkey</span><br><span class="line">        ssh-keygen -t ed25519 -C $&#123;sshkey&#125; # 只是生成的 sshkey 的名称，并不约束或要求具体命名为某个邮箱</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;即将生成sshkey,不需要特别需求时可直接依提示按三次回车!!!&quot;</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;即将打开sshkey,复制后可按 q 返回...&quot;</span><br><span class="line">        sleep 2s</span><br><span class="line">        less ~/.ssh/id_ed25519.pub</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;配置完成,请将sshkey添加到gitee或者github!&quot;</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;【Github】→【登录账号】→【头像】→【Setting】→【SSH and GPG keys 】→【SSH keys】→【New SSH key】&quot;</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;【Gitee】→【登录账号】→【头像】→【账号设置】→【安全设置】→【SSH公钥】→【添加公钥】&quot;</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;https://github.com/settings/keys&quot;</span><br><span class="line">        echo -e &quot;$&#123;INFO&#125;https://gitee.com/profile/sshkeys&quot;</span><br><span class="line">        sleep 2s</span><br><span class="line">    fi</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/85780aad.html">LV01-Git-03-首次运行Git前的配置</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月02日 - 15:14</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/85780aad.html" title="LV01-Git-03-首次运行Git前的配置">https://sumumm.github.io/post/85780aad.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/Git/" rel="tag"><i class="fa fa-tag"></i> Git</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/4d3056dc.html" rel="prev" title="LV01-Git-04-Git本地仓库-01-基础操作">
                  <i class="fa fa-angle-left"></i> LV01-Git-04-Git本地仓库-01-基础操作
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/d0653ac9.html" rel="next" title="LV01-Git-02-Git的安装">
                  LV01-Git-02-Git的安装 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
